package org.jeecg.modules.utill;

import org.jeecg.common.util.RedisUtil;
import org.jeecg.common.util.SpringContextUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author tanxy
 * @date 2022年11月30日 9:55
 */
public class MqttUtil {

    public final static String MATCH_STATUS = "MATCH_STATUS";
    //组ID
    public static Map<String,List<String>> MATCH_GROUPID_MAP=new HashMap<>();
    //比赛运行的map缓存 userid-matchid
    public static Map<String,String> MATCH_MAP=new HashMap<>();
    //1 检录  ； 2 比赛  userid - matchType
    public static Map<String,Integer> MATCH_TYPE_MAP=new HashMap<>();
    // part A 点既是起点也是终点（起终点）   round 绕圈（起点终点不在一起）  AB  a点到b点比赛
    public static Map<String,String> RUNNER_TYPE_MAP=new HashMap<>();

    public static int TIME_INTERVAL=10;

    public static void  start(String userId,String matchId){
        RedisUtil redisUtil = SpringContextUtils.getBean(RedisUtil.class);
        redisUtil.set(MATCH_STATUS+userId,1);
        MATCH_MAP.put(userId,matchId);
    }

    public static void  startSatus(int status,String userId,String matchId){
        if(status==0){
            stop(userId,matchId);
        }else if(status==2){
            start(userId,matchId);
        }
        MATCH_TYPE_MAP.put(userId,status);
    }

    public static void  startSatus(int status,String userId){
        MATCH_TYPE_MAP.put(userId,status);
    }

    public static void  stop(String userId,String matchId){
        RedisUtil redisUtil = SpringContextUtils.getBean(RedisUtil.class);
        redisUtil.set(MATCH_STATUS+userId,0);
        MATCH_TYPE_MAP.remove(userId);
        RUNNER_TYPE_MAP.remove(userId);
        MATCH_GROUPID_MAP.remove(userId);
    }

    public static  boolean status(String userId){
        RedisUtil redisUtil = SpringContextUtils.getBean(RedisUtil.class);
        redisUtil.set(MATCH_STATUS+userId,0);
        int status = (Integer) redisUtil.get(MATCH_STATUS+userId);
        return status==0?false:true;
    }

}
